$(function () {
    var salaryList_datagrid = $("#salaryList_datagrid");
    var sal_dialog = $("#sal_dialog");
    var sal_form = $("#sal_form");
    salaryList_datagrid.datagrid({
        url: '/salaryList/query.do',
        fit: true,
        fitColumns: true,
        columns: [[
            {field: 'mouth', title: '工资表月份', width: 100,formatter:function(value){
                return '<a href="/employee/view.do" >'+value+'</a>'
            }},
            {field: 'enactTime', title: '制定时间', width: 100},
            {field: 'enact', title: '制定人', width: 100, formatter:function (value) {
                return value ? value.username:"";
            }},
            {field: 'approval', title: '审批人', width: 100 ,formatter:function (value) {
                return value ? value.username : "";
            }},
            {
                field: 'status', title: '状态', width: 100, align: 'center', formatter: function (value, row, index) {

                return value ? "已审核" : "<font color='red'>未审核</font>"

            }
            }
        ]],
        singleSelect: true,
        pagination: true,
        toolbar: "#sal_btns",
        sortName: 'hireDate'
    });
    sal_dialog.dialog({
        width: 300,
        height: 400,
        buttons: "#save_btns",
        closed: true,
        onClose: function () {
            sal_form.form('clear');
        }
    });
    $("a[data-cmd]").click(function () {
        var methodName = $(this).data('cmd');
        methodObject[methodName]();
    });
    var methodObject = {
        edit: function () {
            $("#password_tr").hide();
            var row = salaryList_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', "请选中一条数据", 'warning');
                return;
            }
            sal_dialog.dialog('setTitle', '编辑列表');
            sal_dialog.dialog('open');
        },
        reload: function () {
            salaryList_datagrid.datagrid('reload');
        },

        save: function () {
            sal_form.form('submit', {
                url: '/salaryList/updateByPrimaryKey.do',
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示', '保存成功', 'info')
                        methodObject.cancel();
                        salaryList_datagrid.datagrid('reload');
                    } else {
                        $.messager.alert('温馨提示', data.msg, 'error');
                    }
                }
            })
        },
        cancel: function () {
            sal_dialog.dialog('close');
        },
        query: function () {
            var date = $("[name=date]").val();
            salaryList_datagrid.datagrid('load', {
                keyword: date
            })
        }
    }
});



